﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.Dictionary
{
    public partial class Manufacturers : System.Windows.Forms.Form
    {
        public Manufacturers()
        {
            InitializeComponent();
        }

        private void Manufacturers_Load(object sender, EventArgs e)
        {
            InitData();
        }
        private void InitData()
        {
            DataSets.DictionaryTableAdapters.CountriesTableAdapter adapter = new DIProject.DataSets.DictionaryTableAdapters.CountriesTableAdapter();
            adapter.Fill(this.dictionary.Countries,DIProject.Data.Sync.IsAdmin);
            this.manufacturersTableAdapter.Fill(this.dictionary.Manufacturers,DIProject.Data.Sync.IsAdmin);
            toolStripStatusLabel1.Text = "Всего: " + this.dictionary.Manufacturers.Rows.Count.ToString();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView1.Rows[e.RowIndex].Selected = true;
            DataRowView drv = dataGridView1.SelectedRows[0].DataBoundItem as DataRowView;
            if (drv != null)
            {
                DataSets.Dictionary.ManufacturersRow mr = drv.Row as DataSets.Dictionary.ManufacturersRow;
                if (mr != null)
                {
                    ManufacturersDetail md = new ManufacturersDetail(Util.ActionType.Update, mr.Id, this);
                    md.ShowDialog(this);
                }
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            InitData();            
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            ManufacturersDetail md = new ManufacturersDetail(Util.ActionType.Insert, Int32.MinValue, this);
            md.ShowDialog(this);
        }
    }
}